<?php

use yii\helpers\Html;
use yii\bootstrap\Modal;
use yii\helpers\Url;
use common\libs\Constants;
use mdm\admin\components\Helper;
use kartik\grid\GridView;
use backend\modules\guild\models\GuildSearch;

/* @var $this View */
/* @var $searchModel GuildSearch */
/* @var $dataProvider ActiveDataProvider */

$this->title = Yii::t('modules/guild/default', 'Guilds');
$this->params['breadcrumbs'][] = $this->title;

Modal::begin([
    'id'=>'operate-modal',
    'header'=>'<h4 class="modal-title"></h4>'
]);
Modal::end();
$createUrl = Url::toRoute('create');
$viewUrl = Url::toRoute('view');
$updateUrl = Url::toRoute('update');
$uploadUrl = Url::toRoute('upload');
$bankUrl = Url::toRoute('bank');
$gameUrl = Url::toRoute('game');
$masterUrl = Url::toRoute('create-guild-master');
$createTitle = Yii::t('modules/guild/default','Create Guild');
$updateTitle = Yii::t('modules/guild/default','Update Guild');
$viewTitle = Yii::t('modules/guild/default','View Guild');
$uploadTitle = Yii::t('modules/guild/default','Upload Guild');
$bankTitle = Yii::t('modules/guild/default','Guild Bank');
$gameTitle = Yii::t('modules/guild/default','Guild Game');
$masterTitle = Yii::t('modules/guild/default','Create Guild Master');

$js = <<<JS
// 创建操作
$('#create').on('click', function () {
    $('.modal-dialog').removeClass('modal-lg');
    $('.modal-title').html('{$createTitle}');
    $.get('{$createUrl}',
        function (data) {
            $('.modal-body').html(data);
        }
    );
});
// 详情信息
$('.btn-view').on('click', function () {
    $('.modal-dialog').addClass('modal-lg');
    $('.modal-title').html('{$viewTitle}');
    $.get('{$viewUrl}', { id: $(this).closest('tr').data('key') },
        function (data) {
            $('.modal-body').html(data);
        }
    );
});
// 详情信息
$('.btn-bank').on('click', function () {
    $('.modal-dialog').addClass('modal-lg');
    $('.modal-title').html('{$bankTitle}');
    $.get('{$bankUrl}', { id: $(this).closest('tr').data('key') },
        function (data) {
            $('.modal-body').html(data);
        }
    );
});
// 游戏信息
$('.btn-game').on('click', function () {
    $('.modal-dialog').addClass('modal-lg');
    $('.modal-title').html('{$gameTitle}');
    $.get('{$gameUrl}', { id: $(this).closest('tr').data('key') },
        function (data) {
            $('.modal-body').html(data);
        }
    );
});
// 游戏信息
$('.btn-master').on('click', function () {
    $('.modal-dialog').addClass('modal-lg');
    $('.modal-title').html('{$masterTitle}');
    $.get('{$masterUrl}', { id: $(this).closest('tr').data('key') },
        function (data) {
            $('.modal-body').html(data);
        }
    );
});
// 更新操作
$('.btn-update').on('click', function () {
    $('.modal-dialog').removeClass('modal-lg');
    $('.modal-title').html('{$updateTitle}');
    $.get('{$updateUrl}', { id: $(this).closest('tr').data('key') },
        function (data) {
            $('.modal-body').html(data);
        }
    );
});
JS;
$this->registerJs($js);

?>
<div class="guild-index">
    <?php // echo $this->render('_search', ['model' => $searchModel]); ?>
    <?php if(Helper::checkRoute('create')) { ?>
    <p>
        <?= Html::a(Yii::t('modules/guild/default', 'Create Guild'), ['create'],
        [
            'class' => 'btn btn-success',
            'id' => 'create',
            'data-toggle' => 'modal',
            'data-target' => '#operate-modal'
        ]) ?>
    </p>
    <?php }?>

    <?= GridView::widget([
        'dataProvider' => $dataProvider,
        'filterModel' => $searchModel,
        'columns' => [
            ['class' => 'yii\grid\SerialColumn'],
            'guild_sign',
            'guild_name',
            'guild_contact',
            'guild_phone',
            // 'guild_qq',
            // 'guild_status',
            // 'guild_bank',
            // 'guild_game',
             'guild_divide',
            // 'guild_deducted',
             [
                 'attribute'=>'add_time',
                 'value'=>function($model){
                     return date('Y-m-d H:i:s',$model->add_time);
                 }
             ],
    [
        'class' => 'yii\grid\ActionColumn',
        'template' => Helper::filterActionColumn('{create-guild-master}{view}{bank}{game}{update}{delete}'),
        //                'header' => '操作',
        'headerOptions' => [
            'width' => '100px',
        ],
        'buttons' => [
            'create-guild-master' => function($url, $model, $key){
                return Html::a('<span class="glyphicon glyphicon-user"></span>', $url, [
                    'title' => '创建公会管理员',
                    'class' => 'btn btn-default btn-master',
                    'data-toggle' => 'modal',
                    'data-target' => '#operate-modal',
                ]);
            },
            'view' => function($url, $model, $key){
                return Html::a('<span class="glyphicon glyphicon-eye-open"></span>', $url, [
                    'title' => '详情',
                    'class' => 'btn btn-default btn-view',
                    'data-toggle' => 'modal',
                    'data-target' => '#operate-modal',
                ]);
            },

            'bank' => function($url, $model, $key) {
                return Html::a('<span class="glyphicon glyphicon-credit-card"></span>', $url, [
                    'title' => '添加银行信息',
                    'class' => 'btn btn-default btn-bank',
                    'data-toggle' => 'modal',
                    'data-target' => '#operate-modal',
                ]);
            },

            'game' => function($url, $model, $key) {
                return Html::a('<span class="glyphicon glyphicon-dashboard"></span>', $url, [
                    'title' => '添加游戏',
                    'class' => 'btn btn-default btn-game',
                    'data-toggle' => 'modal',
                    'data-target' => '#operate-modal',
                ]);
            },
            'update' => function($url, $model, $key) {
                return Html::a('<span class="glyphicon glyphicon-pencil"></span>', $url, [
                    'title' => '编辑',
                    'class' => 'btn btn-default btn-update',
                    'data-toggle' => 'modal',
                    'data-target' => '#operate-modal',
                ]);
            },
            'delete' => function($url, $model, $key) {
                return Html::a('<span class="glyphicon glyphicon-trash"></span>', $url, [
                    'title' => '删除',
                    'class' => 'btn btn-default',
                    'data' => [
                        'confirm' => '确定要删除么?',
                        'method' => 'post',
                    ],
                ]);
            },
        ],
    ],
],
    ]); ?>
</div>